package com.estore.model;
import java.util.Objects;
<<<<<<< HEAD
import java.util.Set;
import java.util.HashSet;
import java.io.Serializable;

/**
 * 商品实体类
 */
public class Product implements Serializable {

    private static final long serialVersionUID = 1L;
=======
<<<<<<< HEAD
import java.util.Set;
import java.util.HashSet;
/**
 * 商品实体类
 */
//public class Product implements Comparable<Product>{
public class Product {
=======
/**
 * 商品实体类
 */
public class Product implements Comparable<Product> {  // 添加 implements Comparable<Product>
>>>>>>> b11023a79cfe4f1287615efe508da5d11d2455ec
>>>>>>> a0de305f87a075295234338464a9515178f57cde

    private String id;      // 商品ID
    private String name;    // 商品名称
    private double price;   // 价格
    private int stock;      // 库存
<<<<<<< HEAD
    private Set<String> tags; // 商品标签
=======
<<<<<<< HEAD
    private Set<String> tags; // 商品标签
=======
>>>>>>> b11023a79cfe4f1287615efe508da5d11d2455ec
>>>>>>> a0de305f87a075295234338464a9515178f57cde

    public Product(String id, String name, double price, int stock) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.stock = stock;
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> a0de305f87a075295234338464a9515178f57cde
        this.tags = new HashSet<>(); // 如果构造时不传入标签，初始化为空的HashSet
    }

    public Product(String id, String name, double price, int stock, Set<String> tags) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.stock = stock;
        this.tags = tags != null ? tags : new HashSet<>();
<<<<<<< HEAD
=======
=======
>>>>>>> b11023a79cfe4f1287615efe508da5d11d2455ec
>>>>>>> a0de305f87a075295234338464a9515178f57cde
    }

    // Getters and Setters ...
    public String getId() { return id; }
    public void setId(String id) { this.id = id; }
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    public double getPrice() { return price; }
    public void setPrice(double price) { this.price = price; }
    public int getStock() { return stock; }
    public void setStock(int stock) { this.stock = stock; }
<<<<<<< HEAD
    public Set<String> getTags() { return tags; }
    public void setTags(Set<String> tags) { this.tags = tags; }
=======
<<<<<<< HEAD
    public Set<String> getTags() { return tags; }
    public void setTags(Set<String> tags) { this.tags = tags; }

>>>>>>> a0de305f87a075295234338464a9515178f57cde
    @Override
    public String toString() {
        String baseInfo = String.format("ID: %-5s | 名称: %-20s | 价格: ¥%-8.2f | 库存: %d", id, name, price, stock);
        if (tags != null && !tags.isEmpty()) {
            return baseInfo + " | 标签: " + tags;
        }
        return baseInfo;
<<<<<<< HEAD
    }
=======
=======

    @Override
    public String toString() {
        return String.format("ID: %-5s | 名称: %-20s | 价格: ¥%-8.2f | 库存: %d", id, name, price, stock);
>>>>>>> b11023a79cfe4f1287615efe508da5d11d2455ec
    }

>>>>>>> a0de305f87a075295234338464a9515178f57cde
    // 重写 equals 和 hashCode 是一个好习惯，特别是当对象要放入Set或作为Map的key时
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Product product = (Product) o;
        return Objects.equals(id, product.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
<<<<<<< HEAD
}
=======

<<<<<<< HEAD
//    @Override
//    public int compareTo(Product other) {
//        return this.id.compareTo(other.id);
//    }
=======
    // 步骤一：实现 Comparable 接口的 compareTo 方法
    // 按照商品ID的字母顺序进行升序排列
    @Override
    public int compareTo(Product other) {
        return this.id.compareTo(other.id);
    }
>>>>>>> b11023a79cfe4f1287615efe508da5d11d2455ec
}
>>>>>>> a0de305f87a075295234338464a9515178f57cde
